<template>
  <div>
    <nav-header :headerTitle="'反馈建议'" :navBgColor="'#fff'"></nav-header>
    <section class="page">
      <div class="p-content">
        <div class="null16"></div>
        <div class="pc-header">
          <textarea
            v-model="show.feedText"
            cols="30"
            rows="10"
            placeholder="这里可以写您的想要表述的建议或意见，我们会认真处理。"
          ></textarea>
        </div>
        <div class="null86"></div>
        <div class="pc-section">
          <div class="items" v-for="(items,index) in show.productImgArr" :key="index">
            <div class="items-content">
              <img
                class="imgDel"
                src="@/assets/images/release_pic_delete@2x.png"
                alt
                @click="delImg(index)"
              />
              <img class="imgUrl" :src="items" alt />
            </div>
          </div>
          <div class="items" @click="upImg('productImgArr')">
            <div class="items-content">
              <img class="imgUrl" src="@/assets/images/goods_add.png" alt />
            </div>
          </div>
        </div>
      </div>
      <div class="footer">
        <div class="f-btn" @click="save">提交反馈</div>
      </div>
    </section>
  </div>
</template>

<script>
import Vue from "vue";
import { Toast } from "vant";
Vue.use(Toast);
import navHeader from "@/components/NavHeader";
import mixin from "@/utils/mixin";
export default {
  name: "feedback",
  mixins: [mixin],
  components: {
    navHeader
  },
  data() {
    return {
      show: {
        uniqueId: window.localStorage.getItem("uniqueIdByInfluencer"),
        feedText: "",
        productImgArr: [],
        productImgStr: ""
        // productImgArr: [
        //   "https://magicvoicetrans.oss-cn-shenzhen.aliyuncs.com/useinstruct/aos/3/noSuspensionWindow/1.png",
        //   "https://magicvoicetrans.oss-cn-shenzhen.aliyuncs.com/useinstruct/aos/3/noSuspensionWindow/2.png",
        //   "https://magicvoicetrans.oss-cn-shenzhen.aliyuncs.com/useinstruct/aos/3/noSuspensionWindow/3.png"
        // ],
        // productImgStr:
        //   "https://magicvoicetrans.oss-cn-shenzhen.aliyuncs.com/useinstruct/aos/3/noSuspensionWindow/1.png@https://magicvoicetrans.oss-cn-shenzhen.aliyuncs.com/useinstruct/aos/3/noSuspensionWindow/2.png@https://magicvoicetrans.oss-cn-shenzhen.aliyuncs.com/useinstruct/aos/3/noSuspensionWindow/3.png"
      },
      params: {}
    };
  },
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    init: function() {},
    save() {
      if (!this.show.feedText) {
        Toast({
          forbidClick: true,
          message: "请输入您的想要表述的建议或意见!"
        });
        return false;
      }
      this.strImg();
      this.params = {
        uniqueId: this.show.uniqueId,
        feedbackContent: this.show.feedText,
        feedbackImgUrls: this.show.productImgStr
      };
      //alert(JSON.stringify(this.show.productImgStr));
      this.$http.post("user/addFeedbackInfo", this.params).then(
        res => {
          console.log(res);
          Toast.success({
            forbidClick: true,
            message: "保存成功",
            onClose: () => {
              this.$router.go(-1); //返回上一层
            }
          });
        },
        err => {
          console.log(err);
        }
      );
    },
    upImg(type) {
      //alert(type);
      let parmas = {
        maxCount: 1, //选择相册的最大数，若是相机拍照则只能为1
        sourceType: ["album", "camera"], //相册&&拍照，可选其一
        method: "suggestionsImg"
      };
      this.$bridge.callHandler("chooseImages", parmas, res => {
        let imagesArr = res.split(",");
        //alert(JSON.stringify(imagesArr));
        if (type == "productImgArr") {
          //alert(imagesArr[0]);
          this.show.productImgArr.push(imagesArr[0]);
        }
      });
    },
    delImg(index) {
      this.show.productImgArr.splice(index, 1);
      this.strImg();
    },
    strImg() {
       this.show.productImgStr=this.show.productImgArr.join(",");
    }
  }
};
</script>
<style lang="scss" scoped>
.page {
  margin-top: 86px;
  .null16 {
    width: 100%;
    height: 16px;
  }
  .null86 {
    width: 100%;
    height: 86px;
  }
  .p-content {
    padding: 32px;
    .pc-header {
      width: 100%;
      height: 96px;
      font-size: 34px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      textarea {
        width: 100%;
        height: 100%;
      }
      textarea::-webkit-input-placeholder {
        color: rgba(129, 129, 129, 1);
        line-height: 48px;
      }
    }
  }
  .pc-section {
    .items {
      float: left;
      width: 33%;
      .items-content {
        margin: 5px;
        position: relative;
        .imgUrl {
          width: 100%;
          height: 222px;
        }
        .imgDel {
          width: 44px;
          height: 44px;
          position: absolute;
          left: 0px;
          top: 0px;
        }
      }
    }
  }
  .footer {
    width: 100%;
    position: fixed;
    left: 0px;
    bottom: 40px;
    .f-btn {
      width: 686px;
      height: 88px;
      line-height: 88px;
      text-align: center;
      margin: auto;
      background: rgba(255, 37, 37, 1);
      border-radius: 44px;
      font-size: 34px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      color: rgba(255, 255, 255, 1);
    }
  }
}
</style>
